-- card: 11229 from stack: in.3 -- bmap block id: 11379 -- flags: 4000 -- background id: 8327 -- name: AuxWindow ----- HyperTalk script ----- on Install put ChooseTargetStack() into it InstallResource XCMD,AuxWindow,it end Install on opencard set the visible of button "close windows" to false hide card field "demo" hide btn "OK" pass opencard end opencard on closeCard send mouseUp to btn "close windows" end closeCard -- part 5 (field) -- low flags: 01 -- high flags: 2007 -- rect: left=18 top=32 right=287 bottom=384 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Documentation -- part 6 (button) -- low flags: 00 -- high flags: 8003 -- rect: left=299 top=298 right=320 bottom=438 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show C Source ----- HyperTalk script ----- on mouseUp get the visible of card field "source" set the visible of card field "source" to not it if it is false then set the name of me to "Hide C Source" else set the name of me to "Show C Source" end if end mouseUp -- part 9 (button) -- low flags: 00 -- high flags: 0000 -- rect: left=394 top=38 right=132 bottom=484 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Copy This ----- HyperTalk script ----- on mouseUp global window1,window2,gMemOK choose select tool -- just to see if we have enough memory if window1 is empty then put "150,140,250,240" into aRect set the cursor to watch auxWindow "open","aux 1",aRect put the result into window1 put the rect of button 2 into aRect auxWindow "use",window1,arect if window2 is not empty then set the visible of card button swap to true end if else answer "It's window is already up!" choose browse tool end if set the visible of button "close windows" to true end mouseUp -- part 10 (button) -- low flags: 00 -- high flags: 0000 -- rect: left=395 top=141 right=240 bottom=485 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: This Too! ----- HyperTalk script ----- on mouseUp global window2,window1 choose select tool -- just to see if we have enough memory if window2 is empty then put "300,140,400,240" into aRect set the cursor to watch auxWindow "open","aux 2",aRect put the result into window2 put the rect of button 3 into aRect auxWindow "use",window2,arect if window1 is not empty then set the visible of card button swap to true end if else answer "It's window is already up!" choose browse tool end if set the visible of button "close windows" to true end mouseUp -- part 16 (button) -- low flags: 00 -- high flags: A003 -- rect: left=59 top=299 right=322 bottom=202 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show Windows ----- HyperTalk script ----- on mouseUp show card field "demo" show button "OK" end mouseUp -- part 11 (button) -- low flags: 80 -- high flags: 8003 -- rect: left=59 top=299 right=322 bottom=204 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Close Windows ----- HyperTalk script ----- on mouseUp global window1,window2 if window1 is not empty then AuxWindow "close",window1 put empty into window1 end if if window2 is not empty then AuxWindow "close",window2 put empty into window2 end if set the visible of me to false set the visible of button "swap" to false end mouseUp -- part 12 (button) -- low flags: 80 -- high flags: 8003 -- rect: left=402 top=254 right=275 bottom=478 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Swap ----- HyperTalk script ----- on mouseUp global window1,window2 if window1 is not empty and window2 is not empty then set the cursor to watch auxwindow "use",window1,the rect of button 3 auxwindow "use",window2,the rect of button 2 set the visible of button "swap" to false else put "You need both windows up to do this." end if end mouseUp -- part 7 (field) -- low flags: 81 -- high flags: 0007 -- rect: left=18 top=31 right=292 bottom=488 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Source -- part 14 (field) -- low flags: 81 -- high flags: 0004 -- rect: left=18 top=32 right=226 bottom=368 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: demo -- part 15 (button) -- low flags: 80 -- high flags: 8003 -- rect: left=302 top=196 right=218 bottom=357 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: OK ----- HyperTalk script ----- on mouseUp hide me hide card field "demo" end mouseUp -- part contents for card part 5 ----- text ----- AuxWindow Version 1.0d3 Roger Brown AuxWindow is an XCMD that lets you create a new window that is relatively smart in the HyperCard environment. This XCMD does not do anything especially useful, but can serve as a shell for more elaborate operations. As presented here, AuxWindow lets you create any number of auxiliary windows. For each, you specify a name and a frame rectangle. The window created is of type rDocProc with no go-away box. This is important, because a window needs to be disposed using the XCMD "close" operation so that the window pointer is properly purged. An auxiliary window can be dragged around and put in front or behind other windows such as the tools and pattern palettes, desk accessories, and other auxiliary windows. The card window will always stay behind, of course. HyperCard is very smart about managing windows. An auxiliary window will properly update its contents because they are stored as a WindowPicture. (See the LSC code.) One oddity is that you must click on the title bar to activate one of them. This is HyperCard's doing. The XCMD as presented here allows you to open a window and later close it. The script must maintain the window pointer in a global. For HyperCard versions later than 1.1 this business could be hidden in a global that never appears in a script. To do this, you can manage the window pointer in a global accessed from the XCMD using the GetGlobal and SetGlobal call back routines. Use a global name that is unlikely to be used in a script for other purposes, so that it is only known by the XCMD. If you do this, you do not need to pass the window pointer value in and out of the XCMD. If you have more than one auxiliary window open at a time, however, you will need some parameter to identify which window each call to the XCMD is intended for. With this version, you can also use a window to hold a drawing. The code calls back to HyperCard to copy a area of the card's paint layer and installs the copy in the aux window using the clipboard. (See the LSC code.) This version supports color windows, but a copy from HyperCard is not likely to be in color! (The current version of HyperCard at the time of his release is 1.2.2). To try it, click on the patterns marked "Copy This!" and "This Too!" on the right side of this card. The patterns you click on will appear in auxiliary windows. Then move them around a bit with other windows present to see what happens. Press the "Swap" button to see the pictures interchange. Finally, close the windows by pressing the "Close" button. Look at the scripts of these buttons to see how to use the XCMD. INVOKING AuxWindow AuxWindow "open",name of window, frame rect of window the result must be held in a global, this is the Window Pointer AuxWindow "use",window pointer global, rectangle to copy AuxWindow "close", window pointer REVISION HISTORY 1.0d1 7/1/88 add name and frame parameters 1.0d2 7/15/88 add color window support 1.0d3 3/10/89 update for LightSpeed C version 3.0 -- part contents for card part 7 ----- text ----- /* AuxWindow1.0d3.c */ /* © Trustees of Dartmouth College */ /* written in LightSpeed C © Think Technologies, Inc */ /* Roger Brown, Dartmouth Courseware Development Group 3/10/89 */ /* version 1.0d3 update for LSC 3.0 */ /* version 1.0d2 add color window support */ /* version 1.0d1 add name and location rect in open */ /* Creates a floating no go-away window with a picture that is cut from a card. syntax is: AuxWindow "open",name,rectangle of window returns window pointer AuxWindow "use",window pointer,rectangle to copy AuxWindow "close",window pointer */ #include "stddata_ctype.c" #include "QuickDraw.h" #include "WindowMgr.h" #include "MemoryMgr.h" #include "ToolboxUtil.h" #include "strings.c" #include "HyperXCmd.h" #include "XCmdGlue.inc.c" #include "SetUpA4.h" #define FALSE 0 #define TRUE 1 #define HORIZ 1 #define VERT 2 #define VISIBLE 1 /* globals */ XCmdBlockPtr gParamPtr; WindowPtr theWindow; PicHandle itsPic; Str255 theResult; Rect windowRect,grabRect; /* return the max of two ints */ max(a,b) int a,b; { if (a>b) return a; return b; } /* convert a character to upper case */ int toupper(c) char c; { return( (c>='a')&&(c<='z') ? (c-('a'-'A')) : c ); } /* convert a string to upper case */ ucase(s) char *s; { int i,l; l = strlen(s); for (i=0;iparams[1]); strcpy(theNameStr,theName); theRect = *(gParamPtr->params[2]); strcpy(theRectStr,theRect); windowRect.left = GetHCNumberItem(theRectStr,1); windowRect.top = GetHCNumberItem(theRectStr,2); windowRect.right = GetHCNumberItem(theRectStr,3); windowRect.bottom = GetHCNumberItem(theRectStr,4); CreateWindow(theNameStr,&windowRect); NumToString(theWindow,theResult); PtoCstr((char *)theResult); ShowWindow(theWindow); BringToFront(theWindow); } /* use the window to present the copied picture */ UseWindow() { Ptr theWindowPtr; Ptr theRect; Rect badRect; Str255 wPointer; char message[32],theRectStr[32]; GrafPtr gp; theWindowPtr = *(gParamPtr->params[1]); strcpy(wPointer,theWindowPtr); CtoPstr((char *)wPointer); StringToNum(wPointer,&theWindow); theRect = *(gParamPtr->params[2]); strcpy(theRectStr,theRect); grabRect.left = GetHCNumberItem(theRectStr,1); grabRect.top = GetHCNumberItem(theRectStr,2); grabRect.right = GetHCNumberItem(theRectStr,3); grabRect.bottom = GetHCNumberItem(theRectStr,4); itsPic = GetWindowPic(theWindow); if (itsPic != 0L) KillPicture(itsPic); GetMyPicture(); if (GetHandleSize(itsPic) > 0L ) { SetWindowPic(theWindow,itsPic); GetPort(&gp); SetPort(theWindow); SetOrigin(grabRect.left,grabRect.top); SetPort(theWindow); badRect = (*theWindow).portRect; InvalRect(&badRect); SetPort(gp); BringToFront(theWindow); } NumToString(theWindow,theResult); PtoCstr((char *)theResult); } /* close the window */ CloseWindow() { Ptr theWindowPtr; Str255 wPointer; theWindowPtr = *(gParamPtr->params[1]); strcpy(wPointer,theWindowPtr); CtoPstr((char *)wPointer); StringToNum(wPointer,&theWindow); itsPic = GetWindowPic(theWindow); if (itsPic != 0L) KillPicture(itsPic); DisposeWindow(theWindow); strcpy(theResult,"0"); } /* branch on the opcode given in param[0] */ AuxWindow() { Ptr theMessage; char message[32]; theMessage = *(gParamPtr->params[0]); strcpy(message,theMessage); ucase(message); if (strcmp(message,"OPEN")==0) OpenWindow(); else if (strcmp(message,"USE")==0) UseWindow(); else if (strcmp(message,"CLOSE")==0) CloseWindow(); else { /* undefined message */ SysBeep(0); strcpy(theResult,"Undefined message in auxwindow XCMD"); } } /* XCMD enty point */ pascal void main(paramPtr) XCmdBlockPtr paramPtr; { long len; Handle resultHandle; RememberA0(); SetUpA4(); /* to use global variables */ gParamPtr = paramPtr; AuxWindow(); /* run the XCMD */ /* return the result */ len = 1+strlen(theResult); resultHandle = NewHandle(len); HLock(resultHandle); BlockMove(theResult,*resultHandle,len); HUnlock(resultHandle); paramPtr->returnValue = resultHandle; /* all done */ RestoreA4(); return; } -- part contents for card part 14 ----- text ----- Click on the panel labelled "Copy This!". The click on the panel labelled "This Too!" Then push the "Swap" button. Then drag the windows around some. If you get a warning that there is not enough memory to use the paint tools, the demo will not work. To fix it, quit HyperCard and start this stack up again. Go directly to this card by choosing "AuxWindow" from the index.